%define with_tests 1
%define with_doc 0
{% set pypi_name = 'os-xenapi' %}
{% set upstream_version = upstream_version('0.3.4') %}
{% set rpm_release = '1' %}
Name:           {{ py2name() }}
Version:        {{ py2rpmversion() }}
Release:        {{ py2rpmrelease() }}
Summary:        XenAPI library for OpenStack projects
License:        {{ license('Apache-2.0') }}
Group:          Development/Languages/Python
URL:            https://docs.openstack.org/{{ pypi_name }}
Source0:        https://files.pythonhosted.org/packages/source/o/{{ pypi_name }}/{{ pypi_name }}-%{version}.tar.gz
BuildRequires:  openstack-macros
BuildRequires:  {{ py3('devel') }}
BuildRequires:  {{ py3('eventlet') }}
BuildRequires:  {{ py3('oslo.concurrency') }}
BuildRequires:  {{ py3('oslo.i18n') }}
BuildRequires:  {{ py3('oslo.log') }}
BuildRequires:  {{ py3('oslo.utils') }}
BuildRequires:  {{ py3('oslotest') }}
BuildRequires:  {{ py3('paramiko') }}
BuildRequires:  {{ py3('pbr') }}
BuildRequires:  {{ py3('six') }}
BuildRequires:  {{ py3('stestr') }}
BuildRequires:  {{ py3('testscenarios') }}
BuildRequires:  {{ py3('testtools') }}
BuildArch:      noarch

%description
XenAPI library for OpenStack projects.

%package -n {{ py2name(py_versions='py3') }}
Summary:        XenAPI library for OpenStack projects
Requires:       {{ py3('Babel') }}
Requires:       {{ py3('eventlet') }}
Requires:       {{ py3('oslo.concurrency') }}
Requires:       {{ py3('oslo.i18n') }}
Requires:       {{ py3('oslo.log') }}
Requires:       {{ py3('oslo.utils') }}
Requires:       {{ py3('paramiko') }}
Requires:       {{ py3('pbr') }}
Requires:       {{ py3('six') }}

%description -n {{ py2name(py_versions='py3') }}
XenAPI library for OpenStack projects.

%if 0%{?with_doc}
%package -n {{ py2name() }}-doc
Summary:        Documentation for OpenStack log library
BuildRequires:  {{ py3('Sphinx') }}
BuildRequires:  {{ py3('oslosphinx') }}

%description -n {{ py2name() }}-doc
Documentation for the os-xenapi module.
%endif

%prep
%autosetup -p1 -n {{pypi_name }}-%{version}
%py_req_cleanup

%build
%{py3_build}

%if 0%{?with_doc}
# generate html docs
PBR_VERSION=%{version} %sphinx_build -b html doc/source doc/build/html
rm -rf doc/build/html/.{doctrees,buildinfo}
%endif

%install
%{py3_install}

%if 0%{?with_tests}
%check
python3 -m stestr.cli run --test-path ./os_xenapi/tests --black-regex 'os_xenapi.tests.plugins.*'
%endif

%files -n {{ py2name(py_versions='py3') }}
%license LICENSE
%doc ChangeLog README.rst
%{python3_sitelib}/os_xenapi
%{python3_sitelib}/*.egg-info
%{_bindir}/xenapi_bootstrap

%if 0%{?with_doc}
%files -n {{ py2name() }}-doc
%license LICENSE
%doc doc/build/html
%endif

%changelog
